package com.nd.bdc.presto.controller;
import com.nd.bdc.presto.entity.ExecuteMessage;
import com.nd.bdc.presto.util.StringUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * 抽象控制器。
 **
 *
 * @author ggh
 * @date 2020/6/4
 */
public abstract class AbstractController
{

	public static final String CONTENT_TYPE_JSON = "application/json;";


	public AbstractController()
	{
		super();
	}


	protected ResponseEntity<ExecuteMessage> buildExecuteMessageThrowableResponseEntity(Throwable throwable)
	{
		ExecuteMessage operationMessage = ExecuteMessage.valueOfThrowableFail("fail","",throwable);
		return new ResponseEntity<>(operationMessage, HttpStatus.OK);
	}



	/**
	 * 构建操作消息对应的{@linkplain ResponseEntity}。
	 * 
	 * @param message
	 * @return
	 */
	protected ResponseEntity<ExecuteMessage> buildExecuteMessageResponseEntity(String message,String data)
	{
		ExecuteMessage operationMessage = ExecuteMessage.valueOfSuccess("success", message, data);
		return new ResponseEntity<>(operationMessage, HttpStatus.OK);
	}



	/**
	 * 判断对象、字符串、数组、集合、Map是否为空。
	 * 
	 * @param obj
	 * @return
	 */
	protected boolean isEmpty(Object obj)
	{
		return StringUtil.isEmpty(obj);
	}

	/**
	 * 字符串是否为空。
	 * 
	 * @param s
	 * @return
	 */
	protected boolean isEmpty(String s)
	{
		return StringUtil.isEmpty(s);
	}

	/**
	 * 字符串是否为空格串。
	 * 
	 * @param s
	 * @return
	 */
	protected boolean isBlank(String s)
	{
		return StringUtil.isBlank(s);
	}
}
